﻿using System.Reflection;
using System.Web;
using Actya.Core.Infrastructure;
using Actya.Web.Infrastructure.ElFinderConnector;
using Autofac;
using Autofac.Integration.Mvc;
using Module = Autofac.Module;

namespace Actya.Web.Infrastructure.Autofac
{
	public class WebModule : Module
	{
		protected override void Load(ContainerBuilder builder)
		{
			// Register controllers
			builder.RegisterControllers(Assembly.GetExecutingAssembly());

			// Views 
			builder.RegisterSource(new ViewRegistrationSource());

			// Cache
			builder.RegisterType<WebCache>().As<ICache>().SingleInstance();

			// Add sitemap provider to container when enabled.
			if (SiteMap.Enabled)
			{
				builder.RegisterInstance(SiteMap.Provider).AsImplementedInterfaces().ExternallyOwned();
			}

			// ElFinder integration
			builder.RegisterType<ConnectorConfiguration>().InstancePerLifetimeScope();
		}
	}
}